<html>
<head><meta charset="utf-8"><title>sideeffect · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html">sideeffect</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187508046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187508046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187508046">(Feb 05 2020 at 23:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> following up from <a href="https://github.com/rust-lang/compiler-team/issues/177#issuecomment-582653660" target="_blank" title="https://github.com/rust-lang/compiler-team/issues/177#issuecomment-582653660">https://github.com/rust-lang/compiler-team/issues/177#issuecomment-582653660</a> -- I agree it would be good to keep discussion out of those threads:</p>
<p>I wonder why you think self-calls a problem in practice. I would expect us to always lint on that today, with something like this error -- maybe that lint is not yet powerful enough to catch the self-call via trait dispatch though? I wonder if we could detect that.</p>
<p>I imagine self-calls are sufficiently easy to detect and rare enough that we could also add sideeffect calls to them... </p>
<div class="codehilite"><pre><span></span>warning: function cannot return without recursing
 --&gt; src/main.rs:1:1
  |
1 | fn main() {
  | ^^^^^^^^^ cannot return without recursing
2 |     main();
  |     ------ recursive call site
  |
  = note: `#[warn(unconditional_recursion)]` on by default
  = help: a `loop` may express intention better if this is on purpose
</pre></div>



<a name="187555464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187555464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187555464">(Feb 06 2020 at 15:05)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> </p>
<p>We do lint on it, I agree, but people may not fix the lint. It seems like if we can lint on it, we could also prevent UB. =) </p>
<p>Anyway, I'm not sure if it'll be a problem in practice, but as I said it's the only case of this bug in practice that I've encountered. In general, the fact that a function recurses on itself is less obvious and more likely to happen by accident than (I think) writing a purposefully infinite loop that has no side effects (which .. isn't really a very common thing to do?)</p>



<a name="187555686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187555686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187555686">(Feb 06 2020 at 15:07)</a>:</h4>
<p>Hm, yes, I would agree. Though I think writing a infinite loop is more likely to be actually what you wanted</p>



<a name="187555711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187555711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187555711">(Feb 06 2020 at 15:07)</a>:</h4>
<p>But I think we would not want to ban this, right?</p>



<a name="187555728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187555728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187555728">(Feb 06 2020 at 15:07)</a>:</h4>
<p>i.e., we're adding side effect because it is not UB according to "Rust", just UB according to LLVM</p>



<a name="187557016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557016">(Feb 06 2020 at 15:21)</a>:</h4>
<p>Correct</p>



<a name="187557100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557100">(Feb 06 2020 at 15:22)</a>:</h4>
<p>I also don't know how literally you mean <code>loop { }</code></p>



<a name="187557117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557117">(Feb 06 2020 at 15:22)</a>:</h4>
<p>I mean it quite literally :)</p>



<a name="187557122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557122">(Feb 06 2020 at 15:22)</a>:</h4>
<p>It seems like we could do better than that -- basically any <code>loop</code> without function calls</p>



<a name="187557125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557125">(Feb 06 2020 at 15:22)</a>:</h4>
<p>or something like that</p>



<a name="187557155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557155">(Feb 06 2020 at 15:22)</a>:</h4>
<p>er, I mean any loop that doesn't have an exit branch</p>



<a name="187557158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557158">(Feb 06 2020 at 15:22)</a>:</h4>
<p>well, to be exact, any unconditional backedges</p>



<a name="187557160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557160">(Feb 06 2020 at 15:22)</a>:</h4>
<p>without function calls</p>



<a name="187557179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557179">(Feb 06 2020 at 15:23)</a>:</h4>
<p>yeah</p>



<a name="187557187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557187">(Feb 06 2020 at 15:23)</a>:</h4>
<p>I guess any loop whose head node postdominates itself</p>



<a name="187557196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/187557196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#187557196">(Feb 06 2020 at 15:23)</a>:</h4>
<p>er, that's wrong, all nodes postdominate themselves :)</p>



<a name="189847234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/189847234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#189847234">(Mar 05 2020 at 23:09)</a>:</h4>
<p>okay, I've (finally) drafted an initial post here <a href="https://github.com/rust-lang/blog.rust-lang.org/pull/534" target="_blank" title="https://github.com/rust-lang/blog.rust-lang.org/pull/534">https://github.com/rust-lang/blog.rust-lang.org/pull/534</a></p>



<a name="189847242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/sideeffect/near/189847242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/sideeffect.html#189847242">(Mar 05 2020 at 23:09)</a>:</h4>
<p>please provide feedback!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>